import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import SeatSelection from '../views/SeatSelection.vue'

Vue.use(VueRouter)

let beforeEnter = (to,from,next)=>{
  let token = window.localStorage.getItem("token");
  // 判断是否登录
  if(!token){
    next("/login");
    return;
  }else{
    next();
  }
}

const routes = [
  {
    path: '/',
    redirect: '/home',
  },
  {
    path: '/home',
    name: 'home',
    component: HomeView
  },
  {
    path: '/city-list',
    name: 'city-list',
    component: () => import('../views/CitysList.vue')
  },
  {
    path: '/detail',
    name: 'detail',
    component: () => import('../views/MovieDetail.vue')
  },
  {
    path: '/video',
    name: 'video',
    component: () => import('../views/VideoPlay.vue')
  },
  {
    path: '/cinema',
    name: 'cinema',
    component: () => import('../views/CinemaDetail.vue')
  },
  {
    path: '/seat',
    name: 'seat',
    component:SeatSelection
  },
  {
    path: '/videos',
    name: 'videos',
    component: () => import('../views/VideoView.vue')
  },
  {
    path: '/my',
    name: 'my',
    component: () => import('../views/MyView.vue'),
    beforeEnter:beforeEnter,
  },
  {
    path: '/order',
    name: 'order',
    component: () => import('../views/OrderList.vue')
  },
  {
    path: '/wish',
    name: 'wish',
    component: () => import('../views/WishView.vue')
  },
  {
    path: '/ticket',
    name: 'ticket',
    component: () => import('../views/TicketPurchase.vue')
  },
  {
    path: '/shortvideo',
    name: 'shortvideo',
    component: () => import('../views/SmallVideoView.vue')
  },
  {
    path: '/search',
    name: 'search',
    component: () => import('../views/SearchView.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/LoginView.vue'),
  },
  {
    path: '/live',
    name: 'live',
    component: () => import('../views/VideoLivePlay.vue'),
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
